package com.infore.airsupervise.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.infore.airsupervise.R;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.bean.LawingSiteE;
import com.infore.airsupervise.bean.PolluterE;
import com.infore.airsupervise.other.listener.LayoutControl;
import com.infore.airsupervise.other.listener.LayoutControlListener;
import com.infore.airsupervise.ui.fragment.PsonSelectorFragment;
import com.infore.airsupervise.utils.JumpUtil;
import com.infore.airsupervise.utils.ToastUtil;
import com.rey.material.widget.RadioButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @features: 现场监察记录表单 界面
 * @author: WuTao
 * @date: 2017/5/12 16:37
 */
public class SiteRecordCreateActivity extends BaseTitleBarActivity {
    @BindView(R.id.rb_produceStatus_true)
    RadioButton rbProduceStatusTrue;
    @BindView(R.id.rb_produceStatus_false)
    RadioButton rbProduceStatusFalse;
    @BindView(R.id.rb_produceStatus_default)
    RadioButton rbProduceStatusDefault;
    @BindView(R.id.et_produceStatus)
    EditText etProduceStatus;
    @BindView(R.id.rb_examineFail_true)
    RadioButton rbExamineFailTrue;
    @BindView(R.id.rb_examineFail_false)
    RadioButton rbExamineFailFalse;
    @BindView(R.id.rb_examineFail_default)
    RadioButton rbExamineFailDefault;
    @BindView(R.id.et_examineFail)
    EditText etExamineFail;
    @BindView(R.id.rb_threeTogether_true)
    RadioButton rbThreeTogetherTrue;
    @BindView(R.id.rb_threeTogether_false)
    RadioButton rbThreeTogetherFalse;
    @BindView(R.id.rb_threeTogether_default)
    RadioButton rbThreeTogetherDefault;
    @BindView(R.id.et_threeTogether)
    EditText etThreeTogether;
    @BindView(R.id.rb_buildAndAccept_true)
    RadioButton rbBuildAndAcceptTrue;
    @BindView(R.id.rb_buildAndAccept_false)
    RadioButton rbBuildAndAcceptFalse;
    @BindView(R.id.rb_buildAndAccept_default)
    RadioButton rbBuildAndAcceptDefault;
    @BindView(R.id.et_buildAndAccept)
    EditText etBuildAndAccept;
    @BindView(R.id.rb_systeminstall_true)
    RadioButton rbSysteminstallTrue;
    @BindView(R.id.rb_systeminstall_false)
    RadioButton rbSysteminstallFalse;
    @BindView(R.id.rb_systemOperate_true)
    RadioButton rbSystemOperateTrue;
    @BindView(R.id.rb_systemOperate_false)
    RadioButton rbSystemOperateFalse;
    @BindView(R.id.rb_systemInternet_true)
    RadioButton rbSystemInternetTrue;
    @BindView(R.id.rb_systemInternet_false)
    RadioButton rbSystemInternetFalse;
    @BindView(R.id.rb_systemAccept_true)
    RadioButton rbSystemAcceptTrue;
    @BindView(R.id.rb_systemAccept_false)
    RadioButton rbSystemAcceptFalse;
    @BindView(R.id.rb_waterLet_true)
    RadioButton rbWaterLetTrue;
    @BindView(R.id.rb_waterLet_false)
    RadioButton rbWaterLetFalse;
    @BindView(R.id.rb_waterLet_default)
    RadioButton rbWaterLetDefault;
    @BindView(R.id.et_waterLet)
    EditText etWaterLet;
    @BindView(R.id.rb_airLet_true)
    RadioButton rbAirLetTrue;
    @BindView(R.id.rb_airLet_false)
    RadioButton rbAirLetFalse;
    @BindView(R.id.rb_airLet_default)
    RadioButton rbAirLetDefault;
    @BindView(R.id.et_airLet)
    EditText etAirLet;
    @BindView(R.id.rb_defaultWaste_true)
    RadioButton rbDefaultWasteTrue;
    @BindView(R.id.rb_defaultWaste_false)
    RadioButton rbDefaultWasteFalse;
    @BindView(R.id.rb_defaultTransfer_true)
    RadioButton rbDefaultTransferTrue;
    @BindView(R.id.rb_defaultTransfer_false)
    RadioButton rbDefaultTransferFalse;
    @BindView(R.id.rb_dangerWaste_true)
    RadioButton rbDangerWasteTrue;
    @BindView(R.id.rb_dangerWaste_false)
    RadioButton rbDangerWasteFalse;
    @BindView(R.id.rb_dangerTransfer_true)
    RadioButton rbDangerTransferTrue;
    @BindView(R.id.rb_dangerTransfer_false)
    RadioButton rbDangerTransferFalse;
    @BindView(R.id.rb_toteOffice_true)
    RadioButton rbToteOfficeTrue;
    @BindView(R.id.rb_toteOffice_false)
    RadioButton rbToteOfficeFalse;
    @BindView(R.id.rb_wasteLedger_true)
    RadioButton rbWasteLedgerTrue;
    @BindView(R.id.rb_wasteLedger_false)
    RadioButton rbWasteLedgerFalse;
    @BindView(R.id.rb_emergencyCase_true)
    RadioButton rbEmergencyCaseTrue;
    @BindView(R.id.rb_emergencyCase_false)
    RadioButton rbEmergencyCaseFalse;
    @BindView(R.id.et_conclusion)
    EditText etConclusion;
    @BindView(R.id.et_detailRequire)
    EditText etDetailRequire;
    @BindView(R.id.tv_info_arrow)
    AwesomeTextView tvInfoArrow;
    @BindView(R.id.et_permit)
    EditText etPermit;
    @BindView(R.id.et_wasteLicence)
    EditText etWasteLicence;
    @BindView(R.id.et_address)
    EditText etAddress;
    @BindView(R.id.et_corporate)
    EditText etCorporate;
    @BindView(R.id.et_leader_name)
    EditText etLeaderName;
    @BindView(R.id.et_leader_position)
    EditText etLeaderPosition;
    @BindView(R.id.et_leader_phone)
    EditText etLeaderPhone;
    @BindView(R.id.et_checkContent)
    EditText etCheckContent;
    @BindView(R.id.ll_info)
    LinearLayout llInfo;
    @BindView(R.id.ll_condition)
    LinearLayout llCondition;
    @BindView(R.id.tv_condition_arrow)
    AwesomeTextView tvConditionArrow;
    @BindView(R.id.et_onlineData)
    EditText etOnlineData;
    @BindView(R.id.tv_source)
    TextView tvSource;

    private PsonSelectorFragment psonSelectorFra = null; //执法人员选择

    private LayoutControlListener layoutControlListener =null; //控制布局显示影藏
    private PolluterE polluterE;// 被检查的污染源
    private LawingSiteE.RecorderJC recorderE; //监察记录
    private  int position ; //检查记录对应的索引


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_site_record);
        ButterKnife.bind(this);
        Intent it = getIntent();
        if(null != it){
            position = it.getIntExtra(Constants.INTENT_INT_KEY,-1);
            recorderE = (LawingSiteE.RecorderJC) it.getSerializableExtra(Constants.INTENT_OBJ_KEY);
            polluterE = (PolluterE) it.getSerializableExtra("intent_polluter");
        }

        title.setText("现场监察记录");

        rightMenu.setFontAwesomeIcon(FontAwesome.FA_CHECK);
        layoutControlListener = new LayoutControl(ctx);
        initView();
        psonSelectorFra = new PsonSelectorFragment(); //人员选择
        getSupportFragmentManager().beginTransaction().
                replace(R.id.fl_record_psons,psonSelectorFra,null).commit();
        if(null != recorderE){
            setRecorderData();
        }else {
            recorderE = new LawingSiteE.RecorderJC();
            //默认执法人员
            psonSelectorFra.addDefaultPson();
        }
        setPolluterData();

    }

    private void initView() {
        //生产状态
        rbProduceStatusTrue.setOnCheckedChangeListener(checkListener);
        rbProduceStatusFalse.setOnCheckedChangeListener(checkListener);
        rbProduceStatusDefault.setOnCheckedChangeListener(checkListener);
        //未经环评审批的新建项目
        rbExamineFailFalse.setOnCheckedChangeListener(checkListener);
        rbExamineFailTrue.setOnCheckedChangeListener(checkListener);
        rbExamineFailDefault.setOnCheckedChangeListener(checkListener);
        //未执行“三同时”建设项目
        rbThreeTogetherTrue.setOnCheckedChangeListener(checkListener);
        rbThreeTogetherFalse.setOnCheckedChangeListener(checkListener);
        rbThreeTogetherDefault.setOnCheckedChangeListener(checkListener);
        //污染设施建设、验收和运行情况
        rbBuildAndAcceptTrue.setOnCheckedChangeListener(checkListener);
        rbBuildAndAcceptFalse.setOnCheckedChangeListener(checkListener);
        rbBuildAndAcceptDefault.setOnCheckedChangeListener(checkListener);
        //自动监控系统安装情况
        rbSysteminstallTrue.setOnCheckedChangeListener(checkListener);
        rbSysteminstallFalse.setOnCheckedChangeListener(checkListener);
        //自动监控系统运行情况
        rbSystemOperateTrue.setOnCheckedChangeListener(checkListener);
        rbSystemOperateFalse.setOnCheckedChangeListener(checkListener);
        //自动监控系统联网情况
        rbSystemInternetTrue.setOnCheckedChangeListener(checkListener);
        rbSystemInternetFalse.setOnCheckedChangeListener(checkListener);
        //自动监控系统验收情况
        rbSystemAcceptTrue.setOnCheckedChangeListener(checkListener);
        rbSystemAcceptFalse.setOnCheckedChangeListener(checkListener);
        //在线监测数据

        //废水排放情况
        rbWaterLetFalse.setOnCheckedChangeListener(checkListener);
        rbWaterLetTrue.setOnCheckedChangeListener(checkListener);
        rbWaterLetDefault.setOnCheckedChangeListener(checkListener);
        //废气排放情况
        rbAirLetDefault.setOnCheckedChangeListener(checkListener);
        rbAirLetFalse.setOnCheckedChangeListener(checkListener);
        rbAirLetTrue.setOnCheckedChangeListener(checkListener);
        //一般固废
        rbDefaultWasteFalse.setOnCheckedChangeListener(checkListener);
        rbDefaultWasteTrue.setOnCheckedChangeListener(checkListener);
        //一般固废暂存转移
        rbDefaultTransferTrue.setOnCheckedChangeListener(checkListener);
        rbDefaultTransferFalse.setOnCheckedChangeListener(checkListener);
        //危险废物
        rbDangerWasteFalse.setOnCheckedChangeListener(checkListener);
        rbDangerWasteTrue.setOnCheckedChangeListener(checkListener);
        //危险固废暂存转移
        rbDangerTransferFalse.setOnCheckedChangeListener(checkListener);
        rbDangerTransferTrue.setOnCheckedChangeListener(checkListener);
        //环保管理机构
        rbToteOfficeFalse.setOnCheckedChangeListener(checkListener);
        rbToteOfficeTrue.setOnCheckedChangeListener(checkListener);
        //污染设施运行台账
        rbWasteLedgerFalse.setOnCheckedChangeListener(checkListener);
        rbWasteLedgerTrue.setOnCheckedChangeListener(checkListener);
        //环境应急预案
        rbEmergencyCaseFalse.setOnCheckedChangeListener(checkListener);
        rbEmergencyCaseTrue.setOnCheckedChangeListener(checkListener);
        //现场检查结论
        //处理意见及相关要求

    }
    /**
     * 污染源信息
     */
    private void setPolluterData(){
        if(null != polluterE) {
            tvSource.setText(polluterE.getName());
            etAddress.setText(polluterE.getAddress());
            etCorporate.setText(polluterE.getPerson());
        }
    }

    /**
     * 编辑数据
     */
    private void setRecorderData(){
        psonSelectorFra.addPsonList(recorderE.getInspectPson());
        etWasteLicence.setText(recorderE.getWasteLicence());
        etLeaderPosition.setText(recorderE.getLeaderPosition());
        etCheckContent.setText(recorderE.getSupervise());
        etLeaderName.setText(recorderE.getLeaderName());
        etLeaderPhone.setText(recorderE.getLeaderPhone());
        etOnlineData.setText(recorderE.getOnlineData());
        etConclusion.setText(recorderE.getConclusion());
        etDetailRequire.setText(recorderE.getDetailRequire());
        if(!TextUtils.isEmpty(recorderE.getProduceStatus())){ //生产状态
            if(TextUtils.equals(recorderE.getProduceStatus(),rbProduceStatusTrue.getText())){
                rbProduceStatusTrue.setChecked(true);
            }else if(TextUtils.equals(recorderE.getProduceStatus(),rbProduceStatusFalse.getText())){
                rbProduceStatusFalse.setChecked(true);
            }else {
                rbProduceStatusDefault.setChecked(true);
                etProduceStatus.setText(recorderE.getProduceStatus());
                etProduceStatus.setVisibility(View.VISIBLE);
            }
        }
        //未经环评审批的新建项目
        if (radioButtonChoose(recorderE.getExamineFail(),rbExamineFailTrue,rbExamineFailFalse)){
            rbExamineFailDefault.setChecked(true);
            etExamineFail.setText(recorderE.getExamineFail());
            etExamineFail.setVisibility(View.VISIBLE);
        }
        //未执行“三同时”建设项目
        if(radioButtonChoose(recorderE.getThreeTogether(),rbThreeTogetherTrue,rbThreeTogetherFalse)){
            rbThreeTogetherDefault.setChecked(true);
            etThreeTogether.setText(recorderE.getThreeTogether());
            etThreeTogether.setVisibility(View.VISIBLE);
        }
        //污染设施建设、验收和运行情况
        if(radioButtonChoose(recorderE.getBuildAndAccept(),rbBuildAndAcceptTrue,rbBuildAndAcceptDefault)){
            rbBuildAndAcceptDefault.setChecked(true);
            etBuildAndAccept.setText(recorderE.getBuildAndAccept());
            etBuildAndAccept.setVisibility(View.VISIBLE);
        }
        //自动监控系统安装情况
        radioButtonChoose(recorderE.getSystemInstall(),rbSysteminstallTrue,rbSysteminstallFalse);
        radioButtonChoose(recorderE.getSystemAccept(),rbSystemAcceptTrue,rbSystemAcceptFalse);
        radioButtonChoose(recorderE.getSystemInternet(),rbSystemInternetTrue,rbSystemInternetFalse);
        radioButtonChoose(recorderE.getSystemOperate(),rbSystemOperateTrue,rbSystemOperateFalse);
        //废水排放情况
        if(radioButtonChoose(recorderE.getWaterLet(),rbWaterLetTrue,rbWaterLetFalse)){
            rbWaterLetDefault.setChecked(true);
            etWaterLet.setText(recorderE.getWaterLet());
            etWaterLet.setVisibility(View.VISIBLE);
        }
        if(radioButtonChoose(recorderE.getAirLet(),rbAirLetTrue,rbAirLetFalse)){
            rbAirLetDefault.setChecked(true);
            etAirLet.setText(recorderE.getAirLet());
            etAirLet.setVisibility(View.VISIBLE);
        }
        radioButtonChoose(recorderE.getDefaultWaste(),rbDefaultWasteTrue,rbDefaultWasteFalse);
        radioButtonChoose(recorderE.getDefaultTransfer(),rbDefaultTransferTrue,rbDefaultTransferFalse);
        radioButtonChoose(recorderE.getDangerWaste(),rbDangerWasteTrue,rbDangerWasteFalse);
        radioButtonChoose(recorderE.getDangerTransfer(),rbDangerTransferTrue,rbDangerTransferFalse);
        radioButtonChoose(recorderE.getToteOffice(),rbToteOfficeTrue,rbToteOfficeFalse);
        radioButtonChoose(recorderE.getEmergencyCase(),rbEmergencyCaseTrue,rbEmergencyCaseFalse);
        radioButtonChoose(recorderE.getWasteLedger(),rbWasteLedgerTrue,rbWasteLedgerFalse);
    }

    /**
     *  再编辑时 根据数据设置单选按钮的状态
     * @param equals  某一字段的值
     * @param rbTrue
     * @param rbFalse
     * @return
     */
    private boolean radioButtonChoose(String equals, RadioButton rbTrue, RadioButton rbFalse){
        if(!TextUtils.isEmpty(equals)){
            if(TextUtils.equals(equals,rbTrue.getText())){
                rbTrue.setChecked(true);
                return false ;
            }else if(TextUtils.equals(equals,rbFalse.getText())){
                rbFalse.setChecked(true);
                return false ;
            } else {
                return true;
            }
        }
        return false ;
    }

    /**
     * 单选框
     */
    private CompoundButton.OnCheckedChangeListener checkListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                ToastUtil.showShort(ctx, compoundButton.getText().toString());
                switch (compoundButton.getId()) {
                    case R.id.rb_produceStatus_true://生产状态
                    case R.id.rb_produceStatus_false:
                    case R.id.rb_produceStatus_default:

                        rbProduceStatusTrue.setChecked(compoundButton == rbProduceStatusTrue);
                        rbProduceStatusFalse.setChecked(compoundButton == rbProduceStatusFalse);
                        rbProduceStatusDefault.setChecked(compoundButton == rbProduceStatusDefault);
                        if(compoundButton == rbProduceStatusDefault){
                            etProduceStatus.setVisibility( View.VISIBLE );
                        }else {
                            etProduceStatus.setVisibility(View.GONE);
                            recorderE.setProduceStatus(compoundButton.getText().toString());
                        }
                        break;
                    case R.id.rb_examineFail_true://未经环评审批的新建项目
                    case R.id.rb_examineFail_false:
                    case R.id.rb_examineFail_default:

                        rbExamineFailTrue.setChecked(compoundButton == rbExamineFailTrue);
                        rbExamineFailFalse.setChecked(compoundButton == rbExamineFailFalse);
                        rbExamineFailDefault.setChecked(compoundButton == rbExamineFailDefault);
                        if(compoundButton == rbExamineFailDefault){
                            etExamineFail.setVisibility( View.VISIBLE);
                        }else {
                            etExamineFail.setVisibility( View.GONE);
                            recorderE.setExamineFail(compoundButton.getText().toString());
                        }

                        break;
                    //未执行“三同时”建设项目
                    case R.id.rb_threeTogether_true:
                    case R.id.rb_threeTogether_false:
                    case R.id.rb_threeTogether_default:

                        rbThreeTogetherTrue.setChecked(compoundButton == rbThreeTogetherTrue);
                        rbThreeTogetherFalse.setChecked(compoundButton == rbThreeTogetherFalse);
                        rbThreeTogetherDefault.setChecked(compoundButton == rbThreeTogetherDefault);
                        if(compoundButton == rbThreeTogetherDefault){
                            etThreeTogether.setVisibility(View.VISIBLE);
                        }else {
                            etThreeTogether.setVisibility(View.GONE);
                            recorderE.setThreeTogether(compoundButton.getText().toString());
                        }
                        break;
                    //污染设施建设、验收和运行情况
                    case R.id.rb_buildAndAccept_true:
                    case R.id.rb_buildAndAccept_false:
                    case R.id.rb_buildAndAccept_default:

                        rbBuildAndAcceptTrue.setChecked(compoundButton == rbBuildAndAcceptTrue);
                        rbBuildAndAcceptDefault.setChecked(compoundButton == rbBuildAndAcceptDefault);
                        rbBuildAndAcceptFalse.setChecked(compoundButton == rbBuildAndAcceptFalse);

                        if(compoundButton == rbBuildAndAcceptDefault){
                            etBuildAndAccept.setVisibility(View.VISIBLE );
                        }else {
                            etBuildAndAccept.setVisibility(View.GONE);
                            recorderE.setBuildAndAccept(compoundButton.getText().toString());
                        }
                        break;
                    //自动监控系统安装情况
                    case R.id.rb_systeminstall_true:
                    case R.id.rb_systeminstall_false:

                        rbSysteminstallTrue.setChecked(compoundButton == rbSysteminstallTrue);
                        rbSysteminstallFalse.setChecked(compoundButton == rbSysteminstallFalse);
                        recorderE.setSystemInstall(compoundButton.getText().toString());
                        break;
                    //自动监控系统运行情况
                    case R.id.rb_systemOperate_true:
                    case R.id.rb_systemOperate_false:
                        rbSystemOperateTrue.setChecked(compoundButton == rbSystemOperateTrue);
                        rbSystemOperateFalse.setChecked(compoundButton == rbSystemOperateFalse);

                        recorderE.setSystemOperate(compoundButton.getText().toString());
                        break;
                    //自动监控系统联网情况
                    case R.id.rb_systemInternet_true:
                    case R.id.rb_systemInternet_false:
                        rbSystemInternetFalse.setChecked(compoundButton == rbSystemInternetFalse);
                        rbSystemInternetTrue.setChecked(compoundButton == rbSystemInternetTrue);

                        recorderE.setSystemInternet(compoundButton.getText().toString());
                        break;
                    //自动监控系统验收情况
                    case R.id.rb_systemAccept_false:
                    case R.id.rb_systemAccept_true:

                        rbSystemAcceptTrue.setChecked(compoundButton == rbSystemAcceptTrue);
                        rbSystemAcceptFalse.setChecked(compoundButton == rbSystemAcceptFalse);

                        recorderE.setSystemAccept(compoundButton.getText().toString());
                        break;
                    //废水排放情况
                    case R.id.rb_waterLet_true:
                    case R.id.rb_waterLet_false:
                    case R.id.rb_waterLet_default:
                        rbWaterLetFalse.setChecked(compoundButton == rbWaterLetFalse);
                        rbWaterLetTrue.setChecked(compoundButton == rbWaterLetTrue);
                        rbWaterLetDefault.setChecked(compoundButton == rbWaterLetDefault);
                        etWaterLet.setVisibility(
                                compoundButton == rbWaterLetDefault ? View.VISIBLE : View.GONE);
                        if( compoundButton == rbWaterLetDefault ){
                            etWaterLet.setVisibility( View.VISIBLE);
                        }else{
                            etWaterLet.setVisibility(View.GONE);
                            recorderE.setWaterLet(compoundButton.getText().toString());
                        }
                        break;
                    //废气排放情况
                    case R.id.rb_airLet_default:
                    case R.id.rb_airLet_false:
                    case R.id.rb_airLet_true:
                        rbAirLetTrue.setChecked(compoundButton == rbAirLetTrue);
                        rbAirLetFalse.setChecked(compoundButton == rbAirLetFalse);
                        rbAirLetDefault.setChecked(compoundButton == rbAirLetDefault);
                        if(compoundButton == rbAirLetDefault){
                            etAirLet.setVisibility(  View.VISIBLE);
                        }else{
                            etAirLet.setVisibility(  View.GONE);
                            recorderE.setAirLet(compoundButton.getText().toString());
                        }
                        break;

                    //一般固废
                    case R.id.rb_defaultWaste_true:
                    case R.id.rb_defaultWaste_false:
                        rbDefaultWasteTrue.setChecked(compoundButton == rbDefaultWasteTrue);
                        rbDefaultWasteFalse.setChecked(compoundButton == rbDefaultWasteFalse);

                        recorderE.setDefaultWaste(compoundButton.getText().toString());
                        break;
                    //一般固废暂存转移
                    case R.id.rb_defaultTransfer_false:
                    case R.id.rb_defaultTransfer_true:
                        rbDefaultTransferFalse.setChecked(compoundButton == rbDefaultTransferFalse);
                        rbDefaultTransferTrue.setChecked(compoundButton == rbDefaultTransferTrue);

                        recorderE.setDefaultTransfer(compoundButton.getText().toString());
                        break;
                    //危险废物
                    case R.id.rb_dangerWaste_true:
                    case R.id.rb_dangerWaste_false:
                        rbDangerWasteFalse.setChecked(compoundButton == rbDangerWasteFalse);
                        rbDangerWasteTrue.setChecked(compoundButton == rbDangerWasteTrue);

                        recorderE.setDangerWaste( compoundButton.getText().toString());
                        break;
                    //危险废物暂存转移
                    case R.id.rb_dangerTransfer_false:
                    case R.id.rb_dangerTransfer_true:
                        rbDangerTransferFalse.setChecked(compoundButton == rbDangerTransferFalse);
                        rbDangerTransferTrue.setChecked(compoundButton == rbDangerTransferTrue);

                        recorderE.setDangerTransfer( compoundButton.getText().toString());
                        break;
                    //环保管理机构
                    case R.id.rb_toteOffice_true:
                    case R.id.rb_toteOffice_false:
                        rbToteOfficeFalse.setChecked(compoundButton == rbToteOfficeFalse);
                        rbToteOfficeTrue.setChecked(compoundButton == rbToteOfficeTrue);

                        recorderE.setToteOffice( compoundButton.getText().toString());
                        break;
                    //污染设施运行台账
                    case R.id.rb_wasteLedger_false:
                    case R.id.rb_wasteLedger_true:
                        rbWasteLedgerFalse.setChecked(compoundButton == rbWasteLedgerFalse);
                        rbWasteLedgerTrue.setChecked(compoundButton == rbWasteLedgerTrue);

                        recorderE.setWasteLedger( compoundButton.getText().toString());
                        break;
                    //环境应急预案
                    case R.id.rb_emergencyCase_false:
                    case R.id.rb_emergencyCase_true:
                        rbEmergencyCaseTrue.setChecked(compoundButton == rbEmergencyCaseTrue);
                        rbEmergencyCaseFalse.setChecked(compoundButton == rbEmergencyCaseFalse);

                        recorderE.setEmergencyCase( compoundButton.getText().toString());
                        break;
                }

            }
        }
    };


    /**
     * 保存表单数据
     */
    private void initRecorderData(){
        recorderE.setConclusion(etConclusion.getText().toString());//现场检查结论
        recorderE.setDetailRequire(etDetailRequire.getText().toString());//意见要求
        if(rbProduceStatusDefault.isChecked()){
            recorderE.setProduceStatus(etProduceStatus.getText().toString());//生产状态
        }
        if(rbExamineFailDefault.isChecked()){
            recorderE.setExamineFail(etExamineFail.getText().toString());//未经环评
        }
        if(rbThreeTogetherDefault.isChecked()){
            recorderE.setThreeTogether(etThreeTogether.getText().toString());//"三同时"
        }
        if(rbBuildAndAcceptDefault.isChecked()){
            recorderE.setBuildAndAccept(etBuildAndAccept.getText().toString());
        }
        if(rbWaterLetDefault.isChecked()){
            recorderE.setWaterLet(etWaterLet.getText().toString());//废水
        }
        if(rbAirLetDefault.isChecked()){
            recorderE.setAirLet(etAirLet.getText().toString());//废气
        }
        recorderE.setOnlineData(etOnlineData.getText().toString());//在线监测数据
        recorderE.setSupervise(etCheckContent.getText().toString()); //监察内容
        recorderE.setLeaderName(etLeaderName.getText().toString());//负责人姓名
        recorderE.setLeaderPhone(etLeaderPhone.getText().toString());//电话
        recorderE.setLeaderPosition(etLeaderPosition.getText().toString());//职务
        recorderE.setWasteLicence(etWasteLicence.getText().toString()); // 排污许可证
        recorderE.setInspectPson(psonSelectorFra.getAllPsonList()); //执法人员

    }

    @Override
    protected void onRightMenuClick(View view) {
        super.onRightMenuClick(view);
        Intent it = new Intent();
        initRecorderData();
        it.putExtra(Constants.INTENT_OBJ_KEY,recorderE);
        it.putExtra(Constants.INTENT_INT_KEY,position);
        it.putExtra("intent_polluter",polluterE);
        setResult(RESULT_OK,it);
        finish();
    }

    private boolean isInfoShowed = false;
    private boolean isConditionShowed = false;

    @OnClick({R.id.ll_info_control, R.id.ll_condition_control, R.id.tv_source})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_info_control: //基本信息布局控制
                isInfoShowed = !isInfoShowed;
                layoutControlListener.layoutControl(isInfoShowed, llInfo, tvInfoArrow);
                break;
            case R.id.ll_condition_control: // 检查情况 布局控制
                isConditionShowed = !isConditionShowed;
                layoutControlListener.layoutControl(isConditionShowed, llCondition, tvConditionArrow);
                break;
            case R.id.tv_source:
                ToastUtil.showShort(ctx, "选择一个污染源");
                JumpUtil.ForResultJumpFromTo(this, PolluterSearchActivity.class, 200, Constants.INTENT_INT_KEY, 1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200 && resultCode == RESULT_OK) { //返回污染源信息
            polluterE = (PolluterE) data.getSerializableExtra(Constants.INTENT_OBJ_KEY);
            setPolluterData();

        }

    }


}
